//
//  TodayListViewController.m
//  A Cup
//
//  Created by dllo on 15/4/22.
//  Copyright (c) 2015年 doll. All rights reserved.
//

#import "TodayListViewController.h"
#import "ArticleViewController.h"
#import "RadioDetailInfoViewController.h"
#import "AFHTTPRequestOperation.h"
#import "AFHTTPRequestOperationManager.h"
#import "MJRefresh.h"
#import "UIImageView+WebCache.h"
#import "todayListArticleTableViewCell.h"
#import "todayListPhotographTableViewCell.h"
#import "todayListSoundTableViewCell.h"
#import "todayListTopicTableViewCell.h"
#import "todayListTimeLineTableViewCell.h"
#import "todayListModel.h"
#import "imageListModel.h"
#import "todayTopicViewController.h"
#import "todayPhotoViewController.h"
#import "todayTimeLineViewController.h"
#import "User.h"
#import "AboutUsViewController.h"
#import "SaveCupViewController.h"
#import "dataBaseHandle.h"
#import "UMSocial.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
@interface TodayListViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic, retain)UITableView *tableView;
@property(nonatomic, retain)NSMutableArray *array;
@property(nonatomic, assign)NSInteger page;
@property(nonatomic, retain)UIView *logoview;
@property(nonatomic ,retain)UITableView *tabel;
@property(nonatomic, retain)NSMutableArray *arr;
@property(nonatomic, assign)BOOL isclick;
@property(nonatomic, retain)UILabel *namelabel;
@property(nonatomic, retain)UIImageView *perView;
@property(nonatomic, retain)UIImageView *imageView;
@property(nonatomic ,assign)BOOL isclickBu;
@property(nonatomic, retain)UIButton *logobu;
@property(nonatomic, assign)NSInteger textCount;
@property(nonatomic, retain)NSMutableArray *arr2;
@property(nonatomic, assign)BOOL isnight;
@end

@implementation TodayListViewController
// 初始化方法
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.array = [NSMutableArray array];
        self.arr = [NSMutableArray arrayWithObjects:@"夜间模式",@"我的收藏",@"清除缓存" ,@"关于我们",nil];
        self.arr2 = [NSMutableArray arrayWithObjects:@"日间模式",@"我的收藏",@"清除缓存" ,@"关于我们", nil];
        self.isclick = YES;
        self.isclickBu = YES;
        self.isnight = NO;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.title = @"首页";
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, self.view.frame.size.height - 49 - 64)];
    [self.tableView reloadData];
    [self.view addSubview:self.tableView];
    [self.tableView release];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.page = 0;
    [self creatsetView];
    [self method];
    [self.tableView.legendFooter beginRefreshing];
    [self.view bringSubviewToFront:self.tableView];
    [[dataBaseHandle shareDB] openDB];
    [[dataBaseHandle shareDB] creatPlayerTable];
    
    //设置导航栏左按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"set"] style:UIBarButtonItemStylePlain target:self action:@selector(clickset)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor colorWithRed:59/255.0 green:54/255.0 blue:24/255.0 alpha:1];
    //手势 轻扫
    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeActionRight:)];
    [self.tableView addGestureRecognizer:swipeRight];
    swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
    
    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeActionLeft:)];
    [self.tableView addGestureRecognizer:swipeLeft];
    swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
    [swipeRight release];
    [swipeLeft release];
    self.tableView.userInteractionEnabled = YES;
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"Top" forState:UIControlStateNormal];
    button.frame = CGRectMake(0.8 * WIDTH, 0.7 * HEIGHT  - 10, 36, 36);
    button.layer.borderWidth = 1;
    button.backgroundColor = [UIColor blackColor];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.clipsToBounds = YES;
    button.alpha = 0.8;
    button.layer.cornerRadius = 18;
    [button addTarget:self action:@selector(moveToTop) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

// 点击top返回顶部
- (void)moveToTop
{
    self.tableView.contentOffset = CGPointMake(0, 0);
}

- (void)swipeActionRight:(UISwipeGestureRecognizer *)swipe{
    [UIView animateWithDuration:0.25 animations:^{
        self.tableView.frame = CGRectMake(0.70 * WIDTH, 0, self.view.frame.size.width, self.view.frame.size.height);
    } completion:^(BOOL finished) {
                self.tableView.frame = CGRectMake(0.70 * WIDTH, 0, self.view.frame.size.width, self.view.frame.size.height);
    }];
}

- (void)swipeActionLeft:(UISwipeGestureRecognizer *)swipe{
    [UIView animateWithDuration:0.25 animations:^{
        self.tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    } completion:^(BOOL finished) {
        self.tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    }];
}

- (void)creatsetView
{
    self.tabBarController.tabBar.hidden = NO;
    self.logoview = [[UIView alloc] initWithFrame:CGRectMake(0, 0,WIDTH, 120)];
    self.logoview.backgroundColor = [UIColor colorWithRed:59/255.0 green:54/255.0 blue:24/255.0 alpha:1];
    [self.view addSubview:self.logoview];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH/4-8, WIDTH/5+20, WIDTH, 20)];
    label.text = @"Moon White";
    label.textColor = [UIColor whiteColor];
    [self.view addSubview:label];
    
    UIImageView *logview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 120)];
    UIImage * image = [UIImage imageNamed:@"Moon"];
    logview.image = image;
    [self.view addSubview:logview];
//    [self.view sendSubviewToBack:self.logoview];
//    //登录按钮
//    self.logobu = [UIButton buttonWithType:UIButtonTypeSystem];
//    self.logobu.frame = CGRectMake(0.43 * WIDTH, 40, 80, 40);
//    self.logobu.tintColor = [UIColor whiteColor];
//  [self.logobu setTitle:@"登录" forState:UIControlStateNormal];
//    [self.logobu addTarget:self action:@selector(clicklogo) forControlEvents:UIControlEventTouchUpInside];
//    [self.logoview addSubview:self.logobu];
//    
//    //用户名
//    self.namelabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 90, 150, 30)];
//    self.namelabel.textColor = [UIColor whiteColor];
//    [self.logoview addSubview:_namelabel];
//
//    //用户头像
//    self.perView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-zhucedenglutouxiang"]];
//    self.perView.frame = CGRectMake(30, 20, 60, 60);
//    self.perView.layer.cornerRadius = 30;
//    self.perView.layer.masksToBounds = YES;
//    [self.logoview addSubview:self.perView];
    
    self.tabel = [[UITableView alloc] initWithFrame:CGRectMake(0,121, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    self.tabel.backgroundColor = [UIColor colorWithRed:59/255.0 green:54/255.0 blue:24/255.0 alpha:1];
    self.tabel.rowHeight = 70;
    [self.view addSubview:self.tabel];
    [self.view sendSubviewToBack:self.tabel];
    self.tabel.delegate =self;
    self.tabel.dataSource =self;
}

- (void)clicklogo
{
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
    
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        // 获取微博用户名、uid、token等
        if (response.responseCode == UMSResponseCodeSuccess) {
            
            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina];
            
            NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
            NSURL *url = [NSURL URLWithString:snsAccount.iconURL];
            [self.perView sd_setImageWithURL:url];
            self.namelabel.text = snsAccount.userName;
            [dataBaseHandle shareDB].islogin = YES;
            if (self.isclickBu == YES) {
                [self.logobu setTitle:@"切换账号" forState:UIControlStateNormal];
                self.isclickBu = NO;
            }else{
                [self.logobu setTitle:@"登录" forState:UIControlStateNormal];
                self.isclickBu = YES;
            }
        }});
    
    [[UMSocialDataService defaultDataService]requestSnsInformation:UMShareToSina completion:^(UMSocialResponseEntity *response) {
        
        NSLog(@"SnsInformation is %@",response.data);
    }];
    
    [[UMSocialDataService defaultDataService]requestSnsFriends:UMShareToSina completion:^(UMSocialResponseEntity *response) {
        
        NSLog(@"SnsFriends is %@",response.data);
    }];
    
    [[UMSocialDataService defaultDataService] requestUnOauthWithType:UMShareToSina  completion:^(UMSocialResponseEntity *response){
        NSLog(@"response is %@",response);
    }];
}

// 上拉加载  下拉刷新方法
- (void)method
{
    // 下拉刷新
    [self.tableView addLegendHeaderWithRefreshingBlock:^{
        // 因为要保护数组,所以给一个延迟
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 *NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.page = 0;
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        NSString *i = [NSString stringWithFormat:@"%ld",self.page * 10];
        NSDictionary *bodyDic = [NSDictionary dictionaryWithObjectsAndKeys:i,@"start",@"1",@"client",@"31D7DAEA-27EE-4020-ACA7-43F2F7C00C92",@"deviceid",@"10",@"limit",@"",@"auth",@"3.0.0",@"version", nil];
        [manager POST:@"http://api2.pianke.me/pub/today/" parameters:bodyDic success:^(AFHTTPRequestOperation *operation, id responseObject) {
            [self.array removeAllObjects];
            NSMutableDictionary *dic = (NSMutableDictionary *)responseObject;
            NSMutableDictionary *dataDic = [dic objectForKey:@"data"];
            NSMutableArray *arr = [NSMutableArray array];
            arr = [dataDic objectForKey:@"list"];
            for (NSMutableDictionary *todayDic in arr) {
                todayListModel *today = [[todayListModel alloc] init];
                [today setValuesForKeysWithDictionary:todayDic];
                if ([today.enname isEqualToString:@"Material"]||[today.enname isEqualToString:@"Music"]) {
                
                }else{
                    [self.array addObject:today];
                    [today release];
                }
            }
            [self.tableView reloadData];
            [self.tableView.header endRefreshing];
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"%@",error);
        }];
        self.page ++;
     });
    }];
    // 上拉加载
    [self.tableView addLegendFooterWithRefreshingBlock:^{
        [self dataAnalysis];
    }];
}

- (void)dataAnalysis  // 网络解析数据
{
    if ([dataBaseHandle shareDB].state == 1) {
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        NSString *i = [NSString stringWithFormat:@"%ld",self.page * 10];
        NSDictionary *bodyDic = [NSDictionary dictionaryWithObjectsAndKeys:i,@"start",@"1",@"client",@"31D7DAEA-27EE-4020-ACA7-43F2F7C00C92",@"deviceid",@"10",@"limit",@"",@"auth",@"3.0.0",@"version", nil];
        [manager POST:@"http://api2.pianke.me/pub/today/" parameters:bodyDic success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSMutableDictionary *dic = (NSMutableDictionary *)responseObject;
            NSMutableDictionary *dataDic = [dic objectForKey:@"data"];
            NSMutableArray *arr = [NSMutableArray array];
            arr = [dataDic objectForKey:@"list"];
            for (NSMutableDictionary *todayDic in arr) {
                todayListModel *today = [[todayListModel alloc] init];
                [today setValuesForKeysWithDictionary:todayDic];
                if ([today.enname isEqualToString:@"Material"]||[today.enname isEqualToString:@"Music"]) {
                    
                }else{
                    [self.array addObject:today];
                }
                [today release];
            }
            [self.tableView reloadData];
            [self.tableView.footer endRefreshing];
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"%@",error);
        }];
        self.page ++;
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"当前无网络，请检查网络后重新尝试" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.tabel) {
        return 4;
    }
    return self.array.count;
}

#pragma mark -
#pragma mark cell的点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.tabel) {
            if (indexPath.row == 0) {
                if (self.isnight) {
                    [[dataBaseHandle shareDB]day];
                    self.isnight = NO;
                }else{
                    [[dataBaseHandle shareDB] night];
                    self.isnight = YES;
                }
                [self.tabel reloadData];
            }
        if (indexPath.row == 1) {
            SaveCupViewController *saveVC = [[SaveCupViewController alloc] init];
            [self.navigationController pushViewController:saveVC animated:YES];
        }
            if (indexPath.row == 2) {
                NSFileManager *manager = [NSFileManager defaultManager];
                NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
                NSString *path = [paths lastObject];
                NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:path];
                for (NSString *p in files) {
                    NSString *pathi = [path stringByAppendingPathComponent:p];
                    [manager removeItemAtPath:pathi error:nil];
                    self.textCount = files.count;
                }
                if (self.textCount > 3) {
                    NSString *text = [NSString stringWithFormat:@"已成功清除%ld个缓存文件",self.textCount];
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:text delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
                    [alert show];
                }
                else {
                    UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"提示" message:@"已全部清除完成" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
                    [alert show];
                }
            }
        if (indexPath.row == 3) {
            AboutUsViewController *about = [[AboutUsViewController alloc] init];
            [self.navigationController pushViewController:about animated:YES];
        }
    }else{
    todayListModel *today = self.array[indexPath.row];
    if ([today.enname isEqualToString:@"Mor."]||[today.enname isEqualToString:@"Nig."]||[today.enname isEqualToString:@"Book"]||[today.enname isEqualToString:@"World"]||[today.enname isEqualToString:@"Movie"]||[today.enname isEqualToString:@"Psychology"]||[today.enname isEqualToString:@"Interview"]||[today.enname isEqualToString:@"People"]||[today.enname isEqualToString:@"Travel"]) {
        ArticleViewController *article = [[ArticleViewController alloc] init];
        article.conid = today.id;
        article.picUrl = today.coverimg;
        article.sharename = today.title;
        [self.navigationController pushViewController:article animated:YES];
        [article release];
    }else if ([today.enname isEqualToString:@"Sound"]||[today.enname isEqualToString:@"Ears.Theatre"]){
        todayListModel *today = self.array[indexPath.row];
        RadioDetailInfoViewController *tingViewController = [[RadioDetailInfoViewController alloc] init];
        tingViewController.tingid = today.id;
        [self.navigationController pushViewController:tingViewController animated:YES];
        [tingViewController release];
    }else if ([today.enname isEqualToString:@"Topic"]){
        todayTopicViewController *todayTopicController = [[todayTopicViewController alloc] init];
        todayListModel *today = self.array[indexPath.row];
        todayTopicController.idNum = today.id;
        todayTopicController.coverimgString = today.coverimg;
        [self.navigationController pushViewController:todayTopicController animated:YES];
        [todayTopicController release];
    }else if ([today.enname isEqualToString:@"Illustration"]||[today.enname isEqualToString:@"Photo"]){
        todayListModel *today = self.array[indexPath.row];
        todayPhotoViewController *photoController = [[todayPhotoViewController alloc] init];
        photoController.idNum = today.id;
        [self.navigationController pushViewController:photoController animated:YES];
        [photoController release];
    }else if ([today.enname isEqualToString:@"Timeline"]||[today.enname isEqualToString:@"Poem"]){
        todayTimeLineViewController *timeLineController = [[todayTimeLineViewController alloc] init];
        [self.navigationController pushViewController:timeLineController animated:YES];
        todayListModel *today = self.array[indexPath.row];
        timeLineController.idNum = today.id;
        timeLineController.coverimgString = today.coverimg;
        [timeLineController release];
    }else{
        
    }
  }
}

#pragma mark -
#pragma mark 自定义cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.tableView) {
        todayListModel *today = self.array[indexPath.row];
        // 判断Model的enname
        if ([today.enname isEqualToString:@"Sound"]||[today.enname isEqualToString:@"Ears.Theatre"]) {
            return 310;
        }else if ([today.enname isEqualToString:@"Illustration"]||[today.enname isEqualToString:@"Photo"]){
            return (1.45 * WIDTH);
        }else if ([today.enname isEqualToString:@"Timeline"]){
            NSURL *URL = [NSURL URLWithString:today.coverimg];
            UIImageView *imageView = [[UIImageView alloc] init];
            [imageView sd_setImageWithURL:URL placeholderImage:[UIImage imageNamed:@"zhanwei"]];
            CGFloat picheight = imageView.image.size.height * (self.view.frame.size.width - 60) / (imageView.image.size.width + 0.1);
            return 166 + picheight;
        }else if ([today.enname isEqualToString:@"Topic"]){
            NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Helvetica-Bold" size:18],NSFontAttributeName, nil];
            CGRect rect = [today.title boundingRectWithSize:CGSizeMake(WIDTH - 60, 400) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
            return (340 + rect.size.height);
        }else{
            NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Helvetica-Bold" size:18],NSFontAttributeName, nil];
            CGRect rect = [today.title boundingRectWithSize:CGSizeMake(WIDTH - 60, 400) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
            return (380 + rect.size.height)/375 * WIDTH;
        }
    }else{
        return (self.view.frame.size.height - 184)/4;
    }
}

#pragma mark -
#pragma mark cell内容部分
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.tabel) {
        static NSString *reuse = @"reuse25";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse];
            cell.textLabel.textColor = [UIColor whiteColor];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            if (self.isnight) {
                cell.textLabel.text = self.arr2 [indexPath.row];
            }else{
                cell.textLabel.text = self.arr [indexPath.row];
            }
            cell.backgroundColor = [UIColor clearColor];
        }
        return cell;
    }else{
    todayListModel *today = self.array[indexPath.row];
    // 判断Model的enname
#pragma mark cell的Sound部分
    if ([today.enname isEqualToString:@"Sound"]||[today.enname isEqualToString:@"Ears.Theatre"]) {
        static NSString *reuse = @"reuseSound";
        todayListSoundTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[[todayListSoundTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
        }
        cell.headLabel.text = [NSString stringWithFormat:@"%@  ·  %@",today.name,today.enname];
        NSURL *URL = [NSURL URLWithString:today.coverimg];
        [cell.soundImageView sd_setImageWithURL:URL placeholderImage:[UIImage imageNamed:@"zhanwei"]];
        cell.titleLabel.text = today.title;
        NSMutableDictionary *userinfoDic = today.userinfo;
        NSString *uname = [userinfoDic objectForKey:@"uname"];
        cell.authorLabel.text = [NSString stringWithFormat:@"by : %@",uname];
        cell.likeLabel.text = [NSString stringWithFormat:@"%@",today.like];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
#pragma mark cell的Illustration部分
    }else if ([today.enname isEqualToString:@"Illustration"] ||[today.enname isEqualToString:@"Photo"]){
        static NSString *reuse = @"reuseIllustration";
        todayListPhotographTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[[todayListPhotographTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
        }
        NSURL *firstURL = [NSURL URLWithString:today.coverimg];
        [cell.firstImageView sd_setImageWithURL:firstURL placeholderImage:[UIImage imageNamed:@"zhanwei"]];
        NSMutableArray *array = today.imglist;
        NSMutableDictionary *dicZero = [array objectAtIndex:1];
        imageListModel *zero = [[imageListModel alloc] init];
        [zero setValuesForKeysWithDictionary:dicZero];
        NSURL *secondURL = [NSURL URLWithString:zero.imgurl];
        [cell.secondImageView sd_setImageWithURL:secondURL placeholderImage:[UIImage imageNamed:@"zhanwei"]];
        NSMutableDictionary *dicOne = [array objectAtIndex:2];
        imageListModel *one = [[imageListModel alloc] init];
        [one setValuesForKeysWithDictionary:dicOne];
        NSURL *thirdURL = [NSURL URLWithString:one.imgurl];
        [cell.thirdImageView sd_setImageWithURL:thirdURL placeholderImage:[UIImage imageNamed:@"zhanwei"]];
        cell.headLabel.text = [NSString stringWithFormat:@"%@  ·  %@",today.name,today.enname];
        cell.titleLabel.text = today.title;
        // 调节行间距
        cell.introduceLabel.text = today.content;
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:cell.introduceLabel.text];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
        [paragraphStyle setLineSpacing:5];
        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, cell.introduceLabel.text.length)];
        cell.introduceLabel.attributedText = attributedString;
        cell.likeLabel.text = [NSString stringWithFormat:@"%@",today.like];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
#pragma mark cell的Timeline部分
    }else if ([today.enname isEqualToString:@"Timeline"]){
        static NSString *reuse = @"reuseTimeline";
        todayListTimeLineTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[[todayListTimeLineTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
        }
        cell.headLabel.text = [NSString stringWithFormat:@"%@  ·  %@",today.name,today.enname];
        NSURL *URL = [NSURL URLWithString:today.coverimg];
        [cell.timeLineImageView sd_setImageWithURL:URL placeholderImage:[UIImage imageNamed:@"zhanwei"]];
        cell.introduceLabel.text = today.content;
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:cell.introduceLabel.text];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
        [paragraphStyle setLineSpacing:5];
        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, cell.introduceLabel.text.length)];
        cell.introduceLabel.attributedText = attributedString;
        cell.likeLabel.text = [NSString stringWithFormat:@"%@",today.like];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
#pragma mark cell的其他部分
    }else if ([today.enname isEqualToString:@"Topic"]){
        static NSString *reuse = @"reuseTopic";
        todayListTopicTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[[todayListTopicTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
        }
        cell.headLabel.text = [NSString stringWithFormat:@"%@  ·  %@",today.name,today.enname];
        NSURL *URL = [NSURL URLWithString:today.coverimg];
        [cell.articleImageView sd_setImageWithURL:URL placeholderImage:[UIImage imageNamed:@"zhanwei"]];
        cell.titleLabel.text = today.title;
        cell.introduceLabel.text = today.content;
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:cell.introduceLabel.text];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
        [paragraphStyle setLineSpacing:5];
        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, cell.introduceLabel.text.length)];
        cell.introduceLabel.attributedText = attributedString;
        cell.likeLabel.text = [NSString stringWithFormat:@"%@",today.like];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        static NSString *reuse = @"reuse";
        todayListArticleTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[[todayListArticleTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
        }
        cell.headLabel.text = [NSString stringWithFormat:@"%@  ·  %@",today.name,today.enname];
        NSURL *URL = [NSURL URLWithString:today.coverimg];
        [cell.articleImageView sd_setImageWithURL:URL placeholderImage:[UIImage imageNamed:@"zhanwei"]];
        cell.titleLabel.text = today.title;
        cell.introduceLabel.text = today.content;
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:cell.introduceLabel.text];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
        [paragraphStyle setLineSpacing:5];
        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, cell.introduceLabel.text.length)];
        cell.introduceLabel.attributedText = attributedString;
        cell.likeLabel.text = [NSString stringWithFormat:@"%@",today.like];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        }
    }
}
- (void)clickset
{
    if (self.isclick == YES) {
        [UIView animateWithDuration:0.5 animations:^{
            self.tableView.frame = CGRectMake(0.70 * WIDTH, 0, self.view.frame.size.width, self.view.frame.size.height);
        } completion:^(BOOL finished) {
            self.tableView.frame = CGRectMake(0.70 * WIDTH, 0, self.view.frame.size.width,self.view.frame.size.height);
        }];
        self.isclick = NO;
    }else {
        [UIView animateWithDuration:0.5 animations:^{
            self.tableView.frame = CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height);
        } completion:^(BOOL finished) {
            self.tableView.frame = CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height);
        }];
        self.isclick = YES;
    }
}

- (void)dealloc
{
    [_tableView release];
    [_array release];
    [_logoview release];
    [_arr release];
    [_tabel release];
    [_namelabel release];
    [_perView release];
    [_imageView release];
    [_logobu release];
    [_arr2 release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
